package com.bdqn.carrental.controller;

import com.bdqn.carrental.dao.UserJPA;
import com.bdqn.carrental.pojo.UserEntity;
import com.bdqn.carrental.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller //证明是controller层并且返回json
@RequestMapping(value = "/user")
public class UserController {
    @Autowired
    UserService userService;

    /**
     * 查询用户信息
     * @return
     */
    /**
     * @RestController代表这个类是用Restful风格来访问的，如果是普通的WEB页面访问跳转时，我们通常会使用@Controller
    value = "/users/{username}" 代表访问的URL是"http://host:PORT/users/实际的用户名"
    method = RequestMethod.GET 代表这个HTTP请求必须是以GET方式访问
    consumes="application/json" 代表数据传输格式是json
     @PathVariable将某个动态参数放到URL请求路径中
     @RequestParam指定了请求参数名称
     */
    @RequestMapping(value = "/userlist",method = RequestMethod.GET)
    public String  userEntityList(Model model) {
        List<UserEntity> list =userService.findAll();
        model.addAttribute("list",list);
        return "yg-jbxx";
    }

}
